knitr::opts_chunk$set(echo = FALSE)
requireNamespace("pmxTools")
library(PKNCA)
library(dplyr)
library(ggplot2)
library(tidyr)
library(purrr)
breaks_hours <- function(n=5, Q=c(1, 6, 4, 12, 2, 24, 168), ...) {
  n_default <- n
  Q_default <- Q
  function(x, n = n_default, Q=Q_default) {
    x <- x[is.finite(x)]
    if (length(x) == 0) {
      return(numeric())
    }
    rng <- range(x)
    labeling::extended(rng[1], rng[2], m=n, Q=Q, ...)
  }
}

scale_x_hours <- function(..., breaks=breaks_hours()) {
  ggplot2::scale_x_continuous(..., breaks=breaks)
}

Hands-on workshops hints

Hands-on: Steady-state intramuscular administration

The data for the exercise are from a PK study of amikacin in a killer whale and a beluga whale. (DOI: 10.1638/03-078)

(Callback...)

Hands-on: Steady-state intramuscular administration (assignment)

Load the files from the "Hands-on 1_Whale PK" directory, group the data by the "Animal" column, and perform NCA calculations to derive typical parameters such as AUClast, Cmax, and Tmax.

library(PKNCA)
library(tidyverse)

d_conc <- read.csv("2023-10-18-Project D files/Hands-on 1_Whale PK/whale_conc.csv")
d_dose <- read.csv("2023-10-18-Project D files/Hands-on 1_Whale PK/whale_dose.csv")
head(d_conc)
head(d_dose)

o_conc <- PKNCAconc(concentration~time|Animal, data=d_conc)
o_dose <- PKNCAdose(dose~time|Animal, data=d_dose)
o_data <- PKNCAdata(o_conc, o_dose)
o_data$intervals
o_nca <- pk.nca(o_data)
summary(o_nca)
summary(o_nca, drop.group=c())
as.data.frame(o_nca)

Hands-on: Steady-state intramuscular administration (hint)

# Load PKNCA
library(PKNCA)

# Load the data (you may have to adjust the file location based on where you
# saved the files on your computer)
d_conc <- read.csv("2023-10-18-Project D files/Hands-on 1_Whale PK/whale_conc.csv")
d_dose <- read.csv("2023-10-18-Project D files/Hands-on 1_Whale PK/whale_dose.csv")
# Look at the data
head(d_conc)
head(d_dose)

# What PKNCAconc() arguments do you need to provide the concentration data to
# PKNCA?  Fill in between the parentheses with the correct arguments.
o_conc <- PKNCAconc()
# What PKNCAdose() arguments do you need to provide the dose data to PKNCA?
# Fill in between the parentheses with the correct arguments.
o_dose <- PKNCAdose()
# What PKNCAdata() arguments do you need to put the prepared PKNCAconc and
# PKNCAdose objects?  Do you need to add an `intervals` argument? Fill in
# between the parentheses with the correct arguments.
o_data <- PKNCAdata()
# What pk.nca() argument do you need to perform the NCA calculations?
o_nca <- pk.nca()
# What command do you use to get a summary of the NCA calculations?
# What command do you use to get all individual NCA calculations?

Hands-on: Single- and Multiple-dose, single analyte: Setup the underlying datasets (hint)

Objective: Calculate day 1 and steady-state NCA from a single dataset.

  1. Load the data from the "Hands-on 2_Multiple dosing" directory in the "multidose.csv" file.
  2. The columns of interest are "Subject", "time" (time in hours), and "conc" (concentration in mg/L), and "Dose" (the dose in mg/kg).
  3. Generate the dose information with dosing at time 0 and 120 hours from the dataset.
  4. Calculate NCA parameters of AUC~int~, C~max~, and T~max~ on Day 1 and Day 6. And, calculate half-life on Day 6.
# Load PKNCA
library(tidyverse)
library(PKNCA)

# Load the data (you may have to adjust the file location based on where you
# saved the files on your computer)
d_conc <- read.csv("2023-10-18-Project D files/Hands-on 2_Multiple dosing/multidose.csv")
# Look at the data
head(d_conc)

# See what times are available in the data?
d_conc %>%
  select(time, Day) %>%
  unique() %>%
  arrange(time)

# Use this PKNCAconc command to separate by study day
o_conc <- PKNCAconc(data = d_conc, conc~time|Subject)
# What PKNCAdata() arguments do you need to put the prepared PKNCAconc object
# and what intervals do you need to specify?  Fill in between the parentheses
# with the correct arguments.
d_intervals <-
  data.frame(
    start = c(0, 120),
    end = c(24, 144),
    # insert the parameters to calculate here
    aucint.inf.obs = TRUE,
    cmax = TRUE,
    tmax = TRUE
  )
o_data <- PKNCAdata(o_conc, intervals = d_intervals)
o_nca <- pk.nca(o_data)
# Look at your results
summary(o_nca)


billdenney/pknca documentation built on June 11, 2025, 1:49 a.m.